<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>jQuery插件练习</title>
    <link href="../css/bootstrap-3.3.6.min.css" rel="stylesheet">
    <script src="../js/jquery-2.2.0.js"></script>
    <script src="../js/jquery.cookie-1.4.1.js"></script>

    <style>
        body {
            font-family: "微软雅黑";
            font-size: 1.6em;
            color: #02177c;
            background: #faecff;
        }
        a, .glyphicon {
            cursor: pointer;
            margin-right: 5px;
        }
        h3{
            text-align: center;
        }
        #resText1, #resText2, #resText3{
            border:#666 1px solid;
            padding: 10px;
        }
        .text{
            background-color: #00FF00;
        }
    </style>
</head>
<body>
<div class="container">
    <br>
    <h1>jQuery插件练习</h1>
    <hr>
    <br>
    <h3>自定义全局方法插件——$.ltrim()和$.rtrim()</h3>
    <div class="row" >
        <div class="col-md-6 col-md-offset-3">
            <p>这是原文本：
            <span id="text" class="text">&nbsp;&nbsp;&nbsp;&nbsp;前面有4个空格，后面有6个空格&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
            </p>
            <div >
                <div class="well-sm"><b>以下是提交结果:</b></div>
                <strong>应用$.ltrim()方法后：</strong>
                <div id="resText1"></div>
                <strong>应用$.rtrim()方法后：</strong>
                <div id="resText2"></div>
                <strong>应用$.trim()方法后：</strong>
                <div id="resText3"></div>
            </div>
            <hr>
        </div>
    </div>
    <div style="height: 500px"></div>
</div>
<script>
    ;(function($){
        $.extend({
            ltrim:function(text){
                return (text || "").replace( /^\s+/g, "" );
            },
            rtrim:function(text){
                return (text || "").replace( /\s+$/g, "" );
            }
        })
    })(jQuery);

    $("#resText1").wrapInner("<span>"+$.ltrim($("#text").text())+"</span>")
            .find("span").addClass("text");
    $("#resText2").wrapInner("<span>"+$.rtrim($("#text").text())+"</span>")
            .find("span").addClass("text");
    $("#resText3").wrapInner("<span>"+$.trim($("#text").text())+"</span>")
            .find("span").addClass("text");

</script>
<!--<div style="background: rgba(164, 255, 169, 0.34)">.</div>-->
</body>
</html>